// 轮播图
var swiper = new Swiper(".mySwiper", {
    navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
    }, autoplay: true,
    loop: true,
    pagination: {
        el: '.swiper-pagination',
        clickable: true,
    },
})

// api
// 获取元素
// 遍历后改变图片路径及背景颜色
let li=document.querySelectorAll('.api-cont1 li')
li.forEach(function(dom,i){
    dom.addEventListener('mouseover',function(){
        this.style.backgroundColor='#1271ef'
        let imgSrc=this.querySelector('img')
        // console.log(imgSrc)
        imgSrc.src=`../imgs/api0${i+1}-c.svg`
    })
    dom.addEventListener('mouseout',function(){
        this.style.backgroundColor='white'
        let imgSrc=this.querySelector('img')
        imgSrc.src=`../imgs/api0${i+1}.svg`
    })
})


// company
// 需求,跑马灯效果,每隔一定时间后,就切换内容
// 获取元素
let companyList=document.querySelectorAll('.company-list')
let companyCont=document.querySelector('.company-cont1')

let index=0;
// 添加类名函数
function horseRaceLamp(){
    companyList[index].classList.remove('active')
    ++index
    if(index===3) index=0;
    companyList[index].classList.add('active')}
// 计时器调用函数
let timer=setInterval(horseRaceLamp,2000)

// 鼠标移入时,清除计时器
companyCont.addEventListener('mouseover',function(){
    clearInterval(timer)
})
// 鼠标移出时,调用计时器
companyCont.addEventListener('mouseout',function(){
    timer=setInterval(horseRaceLamp,2000)
})



// 需求:回到顶部
// 获取元素
let btn=document.querySelector('.btn')
// 当页面高度大于一定高度时,btn显示,否则隐藏

window.addEventListener('scroll',function(){
let top=document.documentElement.scrollTop
if(top>800){
    btn.style.display='block'
}else{
    btn.style.display='none'

}

})


// btn添加点击事件,点击后回到顶部
btn.addEventListener('click',function(){
    window.scrollTo({
        top: 0,
        behavior: "smooth"
    })
})